Summary

Row

confirmed

552 / 1

active

112.987

update

March 31, 08:45

Column

Notes

Modifying the typical plot of cumulative cases per country, either log or raw scale, to adjust for population. Why?

When comparisons first began, Hubei province and subsequently South Korea, Italy, Spain, Germany and France all have populations of approximtaley 60 Million people and arguably similar standards of living and health care. New Zealand though is an order of magnitude lower and the US nearly an order higher. In simple terms, New Zealand has far less hospital capacity and the US far higher as an absolute value. So absolute values are not interesting, adjusting for population size is.

There is a discrepency with MOH data because for some reason they have decided to report probable cases when no one else does. For consistency the data reverts to that reported by the ECDC overnight.

The top plot show the log of cases vs cumulative cases, both per capita. All countries follow a similar trajectory, but the goal, with interventions is reduce infectioon by COVID-19. When interventions take effect, with this plot there is a rapid fall in the curve. As opposed to the lower plot where the curve gently flattens off.

Per Capita Cases

Plots

Column

Cumulative Cases

Daily Cases plot needs work

Map

World map of cases

Epidemiology

I have a shiny app to deploy here soon

About

The Coronavirus Dashboard: the case of New Zealand

This Coronavirus dashboard provides an overview of the 2019/20 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for New Zealand. This dashboard is built with R using the R Makrdown framework with Flexadashboard. Think of it as a living thing, it will change, like the change of going into a minimum of a month long lockdown. The data will not match that presented each day at 1pm (at the moment), there are differences in how data is reported by various sources, perhaps in time I will switch to the Ministry of Health for the New Zealand Data.

note: I have waited longer to share, but Greig Hamilton is impatient. Some of his work that I helped on can be found here not that he’d ever give me credit for it.

Code

The code behind this dashboard is available on GitHub.

The original layout and first use of data came from Rami Krispin who created both a dashboard and a package with the Johns Hopkins Data

Data

The input data for this dashboard is the dataset available from the European Centre for Disease Prevention and Control

The data and dashboard are refreshed on a daily basis.

Some data is also pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository. But I find that is late to update due to time zone differences.

Contact

For any question or feedback, you can email me or report an issue at the GitHub repo

Update

The data is as of Monday March 30, 2020 and the dashboard has been updated on Tuesday March 31, 2020 at 08:45.

---
title: "**COVID19 - New Zealand**"
author: "**Matt Bixley**"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    source_code: embed
    vertical_layout: fill
    theme: bootstrap
    #logo: images/coronavirus.png
---

  

```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
library(tidyverse)
library(lubridate)
library(scales)

#------------------ Parameters ------------------
# cases today
nzcases = 76
nzdeaths = 0 

options("scipen"=100, "digits"=6)

# plot themes
mytheme <- theme_classic() + 
  theme(legend.position="bottom") +
  theme(axis.line = element_line(colour = "grey50")) + # plot axis to grey
  theme(panel.grid.major = element_line(colour = "grey40", size = 0.4)) + # grid to grey
  theme(panel.grid.minor = element_line(colour = "grey70", size = 0.3)) + # grid to grey
  theme(panel.grid.major.x = element_blank()) + #remove the vertical grid lines 
  theme(panel.grid.minor.x = element_blank()) #remove the vertical grid lines


#------------------ Data ------------------
#source("code/import_jhu.R")
#source("code/population.R")

# read and tidy the ecdc data
source("code/import_ecdc.R")

# function to add the latest NZ data
source("code/insert_today.R")

# don't run the insert code if it morning, ie ecdc updated overnight
ifelse(format(Sys.time(), "%H:%M") < "13:00", 
       covid19,
       covid19 <- insert_today(nzcases = nzcases, nzdeaths = nzdeaths))

nz <- covid19 %>% filter(country == "New_Zealand")

```

Sidebar {.sidebar}
=====================================  

__**The Lockdown Diaries**__

Updates likely 9am NZDT with the over night European data. Just after 1pm NZDT with the New Zealand daily news and sometime in the evening.  

![](images/2019_nCoV.png){ width=100% }

**Monday March 30th** (d5)  
Several requests for the plots to be interactive. Just a heads up, Plotly and ggiraph both destory the formatting of what are already ugly plots. I hate them, so you're not getting them. In time I'll get to letting you choose your own countries. Turns out no one is patient though. Can't have much else to do at the moment. Lucky for me I am not very smart and everything takes a long time, like simple formating, google is my friend. 

Home D going well today even if it is wet, still got some strength done and a run along with a solid day of pissing around with data. I don't think I've ever seen so many people looking at so many variations of the same data. I have the prime office desk, adjacent to the fire.


**Sunday March 29th** (d4)  
Home Loop which means Flagstaff with Ann. Stunning day out. Not sure how many times I've done this loop over the years. It's a lot though and when training is my test piece to see how fit I am. 13k with 600m climb, pb around 69 minutes but who knows, I'm older and senile now.   

![Flagstaff](images/homeloop.jpg){ width=100% }


Moved into the extension, tidied up some plots and over plotted NZ for clarity. Still not happy with how they look, will insert some blow ups to see NZ a bit better. Short story, the curve is flattening.  

**Saturday March 28th** (d3)  
Strength, Run, Walk and moved gear into the new walkin wardrobe  
Bullied to share this link.

**Friday March 27th** (d2)  
Got this dashboard underway  
3x1min Boats, 2x1min Russian Twists  
2x1min Supermans each pair  

**Thursday March 26th** (d1)  
Home D - loving it  
PE instituted for the kids (Not Happy)  
3x20 Pushups  
3x10 Squat Jumps  
30 minute run  

**Wednesday March 25th** (d-1)  
Mitre10 for Paint rollers and bits and pieces  
NZDataScience Zoom Morning Tea  
Builders cleaned the windows  
Sparky rigged up the Hotwater Cylinder in the extension (good bastard)  
3x1min Boats  
2x1min Russian Twists  
3x10 Forward Lunges  
30 minute run  

**Tuesday March 24th** (d-2)  
Set up the home office, nipped down to work for a chair  
5x1min Planks  
3x10 Reverse Lunges  
30 minute run  


**Summary**
=======================================================================

Row
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}
#valueBox(value, subtitle, icon = NULL, color = "aqua", width = 4,href = NULL)
valueBox(
  value = paste0(max(nz$cum_cases)," / ",max(nz$cum_deaths)),
  caption = "Cases / Deaths",
  icon = "fas fa-user-md",
  color = "silver"
)
```


### active {.value-box}

```{r}
valueBox(
  value = max(nz$per_million),
  caption = "Cases per million",
  icon = "fas fa-user-md",
  color = "silver"
)
```

### update {.value-box}

```{r}
valueBox(
  value = paste0(format(Sys.time(), "%B %d"),", ",format(Sys.time(), "%H:%M")),
  caption = "Updated",
  icon = "fas fa-clock",
  color = "silver"
)
```

Column {data-width=600}
-------------------------------------


### **Notes**  
Modifying the typical plot of cumulative cases per country, either log or raw scale, to adjust for population. Why?  

When comparisons first began, Hubei province and subsequently South Korea, Italy, Spain, Germany and France all have populations of approximtaley 60 Million people and arguably similar standards of living and health care. New Zealand though is an order of magnitude lower and the US nearly an order higher. In simple terms, New Zealand has far less hospital capacity and the US far higher as an absolute value. So absolute values are not interesting, adjusting for population size is. 

There is a discrepency with [MOH](https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-current-situation/covid-19-current-cases) data because for some reason they have decided to report probable cases when no one else does. For consistency the data reverts to that reported by the ECDC overnight.  

The top plot show the log of cases vs cumulative cases, both per capita. All countries follow a similar trajectory, but the goal, with interventions is reduce infectioon by COVID-19. When interventions take effect, with this plot there is a rapid fall in the curve. As opposed to the lower plot where the curve gently flattens off.  


```{r fig.width=2, fig.height=2, eval=FALSE}
# plot nz growth
#who <- "New Zealand"
who <- c("New_Zealand", "Australia", "USA", "Italy", "China", "South_Korea", "Spain", "France", "Germany", "United_Kingdom")
fiveper <-  covid19 %>% filter(country %in% who, per_million > 5) %>%
  group_by(country) %>% 
  mutate(days5 = dense_rank(date))
fivenz <- fiveper %>% filter(country == "New_Zealand")

p1 <- fiveper %>% 
  ggplot(aes(x = days5, y = per_million, colour = country)) +
  geom_point() +
  geom_line() +
  labs(title = "Per Capita Cumulative Cases",
  subtitle = "days since 5 cases per million",
  x = "Days", y = "Cases\n(per Million People)") +
  scale_y_continuous(breaks = seq(0, 10000, 500)) +
  # overplot NZ
  geom_point(data = fivenz, aes(x = days5, y = per_million, colour = country), size = 3) +
  geom_line(data = fivenz, aes(x = days5, y = per_million, colour = country))

p1 + mytheme + labs(caption = "Matt Bixley") + 
  scale_colour_brewer(palette = "Paired")
```

  
### **Per Capita Cases**  

```{r, fig.width=8, fig.height=8, fig.align='center'}
# log log of percapita nz growth
# gganimate, should show fall off in incidence when effective measure take over

who <- c("Australia", "USA", "Italy", "China", "South_Korea", "Spain", "France", "Germany", "United_Kingdom", "Taiwan", "Singapore")

nzdat <- covid19 %>% filter(country == "New_Zealand", cases > 0)
plotdata <- covid19 %>% filter(country %in% who, cases_million < 2000, cases > 0, population > 4800000)

p4 <-  plotdata %>% 
 
  ggplot(aes(x = per_million, y = cases_million, group = country)) +
  geom_point(col = "grey30", alpha = 0.3) +
  geom_line(col = "grey30", alpha = 0.3) +
  labs(title = "Beating the Curve",
       subtitle = "When restrictions take affect",
       x = "log of Cumulative Cases\n(per Million)", y = "log of Daily Cases\n(per Million)") +
  
  
  # label the last point
  #geom_point(data = plotdata %>% filter(date == max(date)), 
  #           aes(x = per_million, y = cases_million)) +
  geom_text(data =  plotdata %>% filter(date == max(date)), 
            aes(label=country),hjust=0, vjust=0, size = 3, size = 3, colour = "blue") +

  # overplot NZ
  geom_point(data = nzdat, aes(x = per_million, y = cases_million), size = 3, colour = "red", alpha = 0.5) +
  geom_line(data = nzdat, aes(x = per_million, y = cases_million), size = 1.5, colour = "red", alpha = 0.5) +
  geom_text(data = nzdat %>% filter(date == max(date)), aes(label=country),hjust=0, vjust=0, size = 5, colour = "red") +
  
  # log scales
  scale_y_continuous(trans = "log10", breaks = c(0, 1, 10, 100,1000),
                     minor_breaks = c(seq(0,1,0.1),
                                      seq(1,10,1),
                                      seq(10,100,10),
                                      seq(100,1000,100))) +
  scale_x_continuous(trans = "log10", labels = c(0, 10, 100, 1000,10000),
                     breaks = c(0, 10, 100, 1000,10000),
                     minor_breaks = c(seq(0, 10,1),
                                      seq(0, 100, 10),
                                      seq(100, 1000, 100),
                                      seq(1000, 10000, 1000)))

p4 + theme_classic() + 
  theme(legend.position=NULL) +
  theme(axis.line = element_line(colour = "grey50")) + # plot axis to grey
  theme(panel.grid.major = element_line(colour = "grey40", size = 0.4)) + # grid to grey
  theme(panel.grid.minor = element_line(colour = "grey70", size = 0.3)) + # grid to grey
  labs(caption = "Matt Bixley") + theme(legend.position="none")



```

**Plots**
=======================================================================


Column {data-width=400}
-------------------------------------


### **Cumulative Cases**
    
```{r}

#----------------------------------------
# Plotting the data
who <- c("New_Zealand", "Australia", "USA", "Italy", "China", "South_Korea", "Spain", "France", "Germany", "United_Kingdom")

dayssince <- covid19 %>% filter(country %in% who , cum_cases > 0) %>%
  group_by(country) %>% 
  mutate(days = dense_rank(date))

daysnz <- dayssince %>% filter(country == "New_Zealand")

p2 <- dayssince %>% 
  ggplot(aes(x = days, y = cum_cases, colour = country)) +
  geom_point() +
  geom_line() +
  geom_point(data = daysnz, aes(x = days, y = cum_cases, colour = country), size = 3) +
  geom_line(data = daysnz, aes(x = days, y = cum_cases, colour = country)) +
  #scale_x_continuous(trans = "log10") +
  scale_y_continuous(trans = "log10", labels = sprintf("%.0f", c(0, 10, 100, 1000,10000,100000,1000000)),
                     breaks = c(0, 10, 100, 1000,10000,100000,1000000),
                     minor_breaks = c(seq(0, 10, 2.5),
                                      seq(0, 100, 25),
                                      seq(100, 1000, 250),
                                      seq(1000, 10000, 2500),
                                      seq(10000, 100000, 25000))) +
  labs(title = "Cumulative Cases", subtitle = "Days since 1st case",
        x = "Days", y = "Cumulative Cases\n(log10") +
  theme(axis.text.y = element_text(size = 4))

p2 + mytheme + labs(caption = "Matt Bixley") + 
  scale_colour_brewer(palette = "Paired")


```
 
### **Daily Cases** plot needs work  

```{r}
who <- c("New_Zealand", "Australia", "USA", "Italy", "China", "South_Korea", "Spain", "France", "Germany", "United_Kingdom", "Norway")

#who <- covid19 %>% filter(cum_cases > 400) %>% 
#  select(country) %>% 
#  distinct()

#p3 <- covid19 %>% filter(country %in% who$country) %>%
p3 <- covid19 %>% filter(country %in% who) %>%
  #mutate(daily_million = ifelse(daily_million == 0, NA, daily_million)) %>% 
  ggplot(aes(x = date, y = country, fill = cases_million)) + 
  geom_tile(colour = "white") + 
  scale_fill_gradient(low = "white", high = "orangered4", 
                      name = "Cases per Million") +
  ggtitle("Per Capita Case Incidence") +
  xlab("Days") + ylab("Cases/Million")
 

p3 + mytheme + labs(caption = "Matt Bixley") + 
  scale_fill_gradient(low = "#FFF5EB", high = "#D94801") +
  #scale_colour_brewer(palette = "Oranges") +
  theme(panel.grid.major.y = element_blank()) + 
  theme(panel.grid.minor.x = element_blank())

```


**Map**
=======================================================================

### **World map of cases**


```{r}

library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
#library(stringr)
#library(maps)

options(scipen = 999) ## To disable scientific notation

plain <- theme(
    axis.text = element_blank(),
    axis.line = element_blank(),
    axis.ticks = element_blank(),
    panel.border = element_blank(),
    panel.grid = element_blank(),
    axis.title = element_blank(),
    panel.background = element_rect(fill = "white"),
    plot.title = element_text(hjust = 0.5),
    legend.position = "bottom")

world <- ne_countries(scale = "medium", returnclass = "sf")

worldcov <- world %>% inner_join(.,covid19, by = c("su_a3" = "countryterritoryCode")) %>% 
  filter(per_million < 1500, date == "2020-03-30")

p <- ggplot(data = worldcov) +
  labs(title = "Golobal Cumulative density of COVID19",
       fill = "Cumulative Cases\n(per Million)") +
  geom_sf(aes(fill = per_million)) +
  scale_fill_gradient(low = "#FDD0A2", high = "#D94801")

p + theme_classic() + plain
```


**Epidemiology**
=======================================================================

I have a shiny app to deploy here soon


**About**
=======================================================================

**The Coronavirus Dashboard: the case of New Zealand**

This Coronavirus dashboard provides an overview of the 2019/20 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for New Zealand. This dashboard is built with R using the R Makrdown framework with Flexadashboard. Think of it as a living thing, it will change, like the change of going into a minimum of a month long lockdown. The data will not match that presented each day at 1pm (at the moment), there are differences in how data is reported by various sources, perhaps in time I will switch to the [Ministry of Health](https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus) for the New Zealand Data.

note: I have waited longer to share, but Greig Hamilton is impatient. Some of his work that I helped on can be found [here](http://www.rogaine-results.com/) not that he'd ever give me credit for it.

**Code**

The code behind this dashboard is available on [GitHub](https://github.com/mattbixley/covid19){target="_blank"}.

The original layout and first use of data came from [Rami Krispin](https://github.com/RamiKrispin/coronavirus_dashboard){target="_blank"} who created both a dashboard and a package with the Johns Hopkins Data [![](images/coronavirus.png){ width=3%}](https://github.com/RamiKrispin/coronavirus){target="_blank"}


**Data**

The input data for this dashboard is the dataset available from the
[![](images/logo-ecdc.png){ width=3%}](https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide){target="_blank"} European Centre for Disease Prevention and Control

The data and dashboard are refreshed on a daily basis.

Some data is also pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/CSSEGISandData/COVID-19){target="_blank"}.
But I find that is late to update due to time zone differences.

**Contact**

For any question or feedback, you can email me  or report an issue at the [GitHub repo](https://github.com/MattBixley/COVID19/issues){target="_blank"}

**Update**

The data is as of `r format(max(covid19$date), "%A %B %d, %Y")` and the dashboard has been updated on `r format(Sys.time(), "%A %B %d, %Y")` at `r format(Sys.time(), "%H:%M")`.